<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\BaseController;
use App\Service\Api\WangguiApiService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;

class WangguiApiController extends BaseController
{

    /**
     * 导入网规预测数据
     * @param Request $request
     * @return JsonResponse
     * @throws ValidationException
     */
    public function importWgPrediction(Request $request): JsonResponse
    {
        $this->validate($request, [
            'url' => 'required|string'
        ]);

        $fileUrl = (string)$request->get('url');
        $type    = (string)$request->get('type', '');

        ini_set('max_execution_time', '600');
        ignore_user_abort(true);

        WangguiApiService::importWgPrediction($fileUrl, $type);

        return $this->success();
    }

}
